const app = require('./app/server/config/express.js');
const config = require('./app/server/config/env/config_development.json');
const http = require('http');
const winston = require('winston');
let server = http.createServer(app);

//Socket
var sockets = [];
var num = 0;
var io = require('socket.io')(server);
io.on('connection', function(socket) {
    // console.log(socket)
    console.log(socket.client.id + " connented")
    sockets.push(socket.client.id)
    socket.join(sockets)

    //接收并处理客户端
    socket.on('new_verify', function(data) {
		num++;
        socket.broadcast.emit('notify_verify',num);
	});

	//清除计数器
    socket.on('read', function(data) {
		num = 0;
    })
});

server.listen(config.APP.port);

// exception handling
process.on('uncaughtException', function(err) {
	winston.error('Caught exception:', err);
});

// Expose app
exports = module.exports = app;

// Logging initialization
winston.info('--');
winston.info(config.APP.title, 'application started');
winston.info('Environment:\t\t\t', process.env.NODE_ENV);
winston.info('Port:\t\t\t\t', config.APP.port);
if (process.env.NODE_ENV === 'secure') {
	winston.info('HTTPs:\t\t\t\ton');
}
winston.info('--');
